/**
 * Created by seeker910 on 2018/3/6.
 *
 * 小区基本信息+楼栋信息列表
 */
Rsd.define('Rsd.Faith.dialogs.InfoXiaoQuWuYeDialog', {
    extend: 'Rsd.view.MajorSubDialog',
    requires: [
        'Rsd.controlEx.MajorSubViewer',
        'Rsd.Faith.stores.ListStore'
    ],
    title:'小区详情',
    sub: {
        fk:'XiaoQuBianHao',
        toolBar:{
            xtype:'grid-tool-bar-simple',
            newButtons:[
                {xtype:'label',text:'★ 下方列表为该小区楼栋列表，信息来自房屋信息👇'}
            ]},
        columns: [
            {
                "text": "序号",
                "xtype": "index",
                "width": 40,
                "sortable": false
            },
           /* {
                "xtype": "string",
                "name": "XiaoQuBianHao",
                "text": "小区编号",
                "sortable": false,
                "width": 80,
                "nobr": true
            },*/
            {
                "xtype": "string",
                "name": "LouDongHao",
                "text": "楼栋号",
                "sortable": false,
                align:'center',
                "width": 100,
                //"format":"format_loudonghao",
                "nobr": true
            },
            {
                "xtype": "string",
                "name": "DanYuanHao",
                "text": "单元号",
                align:'center',
                "sortable": false,
                "width": 100
            },
            {
                "xtype": "number",
                "name": "HuShu",
                "text": "户数",
                "precision": 0,
                "sortable": false,
                "width": 50,
                "nobr": true
            },
            {
                "name": "Remark",
                "text": "备注",
                "sortable": false,
                "width": 100,
                "nobr": true
            },
            {
                xtype:'template',
                align:'center',
                "format":"format_tpl",
                "text": "操作",
                "width": 80
            }
        ]
    },
    major: {
        modelType:'Rsd.Faith.Models.InfoXiaoQuWuYeBiaoModel',
        height:170,
        legend: '基本信息',
        key:'BianHao',
        "fields": [

                {
                    "name": "BianHao",
                    "label": {
                        "width": 80,
                        "content": "编号"
                    },
                    "dataIndex": "BianHao",
                    "index": 1,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 20
                },
                {
                    "name": "MingCheng",
                    "label": {
                        "width": 80,
                        "content": "名称"
                    },
                    "dataIndex": "MingCheng",
                    "index": 2,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 100
                },
                {
                    "name": "ZongDongShu",
                    "label": {
                        "width": 80,
                        "content": "总栋数"
                    },
                    "dataIndex": "ZongDongShu",
                    "index": 3,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 10
                },
                {
                    "name": "ZongTaoShu",
                    "label": {
                        "width": 80,
                        "content": "总套数"
                    },
                    "dataIndex": "ZongTaoShu",
                    "index": 4,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 10
                },
                {
                    "name": "JianZhuMianJi",
                    "label": {
                        "width": 80,
                        "content": "建筑面积"
                    },
                    "dataIndex": "JianZhuMianJi",
                    "index": 5,
                    "exist": true,
                    "xtype": "number",
                  width:350,
                    "precision": 2
                },
                {
                    "name": "JianChengRiQi",
                    "label": {
                        "width": 80,
                        "content": "建成日期"
                    },
                    "dataIndex": "JianChengRiQi",
                    "index": 6,
                    "exist": true,
                    "xtype": "date",
                  width:350,
                    "formatString": "yyyy-MM-dd"
                },
                {
                    "name": "KaiFaShangBianHao",
                    "label": {
                        "width": 80,
                        "content": "开发商编号"
                    },
                    "dataIndex": "KaiFaShangBianHao",
                    "index": 7,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 20
                },
                {
                    "name": "WuYeGongSiBianHao",
                    "label": {
                        "width": 80,
                        "content": "物业公司编号"
                    },
                    "dataIndex": "WuYeGongSiBianHao",
                    "index": 8,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 20
                },
                {
                    "name": "YeWeiHuiBianHao",
                    "label": {
                        "width": 80,
                        "content": "业委会编号"
                    },
                    "dataIndex": "YeWeiHuiBianHao",
                    "index": 9,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 20
                },
                {
                    "name": "DiZhi",
                    "label": {
                        "width": 80,
                        "content": "地址"
                    },
                    "dataIndex": "DiZhi",
                    "index": 10,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 200
                },
                {
                    "name": "SuoShuDiQu",
                    "label": {
                        "width": 80,
                        "content": "所属地区"
                    },
                    "dataIndex": "SuoShuDiQu",
                    "index": 11,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 20
                },
                {
                    "name": "Remark",
                    "label": {
                        "width": 80,
                        "content": "备注"
                    },
                    "dataIndex": "Remark",
                    "index": 200,
                    "exist": true,
                    "xtype": "text",
                  width:350,
                    "length": 100
                }
            ]
        
    },
    width: 1200,
    height: 600,
    showClose:true,
    /*
     *
     * */
    constructor :function constructor(config) {
        config = config || {};
        this.apply(config);

    },
    format_loudonghao:function format_loudonghao(row) {

        return [ Rsd.text(row['LouDongHao']||'-')]
    },
    format_tpl:function(row)
    {
        if(Rsd.isEmpty(row['LouDongHao']))
        {
            return [];
        }
        var me = this;
        //report.exportexcel
        var s = Rsd.app.getService('report.exportexcel');

        var  btnExport = document.createElement('a');
        btnExport.href=s.server.url + '?xiaoqubianhao='+row['XiaoQuBianHao']+'&loudonghao='+row['LouDongHao'] + '&___key='+Rsd.app.token;
        btnExport.innerHTML = '发票导出';

        $(btnExport).click (function(){
            me.showLoading('正在下载...');
            setTimeout(function () {
                me.closeLoading();
            },2000);
        });


        return [btnExport]
    },
    load:function load(row) {


        var me = this;
        var _row = row||this.data;
        if( Rsd.isString(_row))//如果是小区编号
        {
            var _bian_hao = _row;
            Rsd.app.getService('info.GetXiaoQuAndLouDongList').requestJson({xiaoqubianhao:_bian_hao},function(data ){
                //console.log(data);
                me.callParentFn('load',[data.data.XiaoQu,data.data.LouDongList]);

            });
        }else//如果是小区对象
        {
            var _bian_hao = _row['BianHao'];

            Rsd.app.getService('info.getloudonglist').requestJson({xiaoqubianhao:_bian_hao},function(data ){

                me.callParentFn('load',[_row,data.data]);

            });

        }

        //
    }
});